home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byte0387.arc / DAWSON.ARC / ILIST.DOC next >
Encoding:
Text File  |  1985-07-12  |  4.5 KB  |  177 lines

  1. listing 1 
  2.  
  3. /*  Point process area starting at x,y = 0,0 and of size *
  4.  *  XSIZE,YSIZE.                     */
  5.   for (y = 0 ; y < YSIZE ; y++) {
  6.     for (x = 0 ; x < XSIZE ; x++) {
  7.         write_pixel(x,y,  pfun(read_pixel(x,y),x,y) );
  8.     }
  9.   }
  10.  
  11.  
  12.  
  13.  
  14. listing 2 
  15.  
  16. /* Use long values as sum could be over 16 bits */
  17.   long h[256];
  18. /* zero histogram array */
  19.   for (i = 0 ; i < 256 ; i++) h[i] = 0L;
  20. /* Scan area and count pixel values */
  21.   for (y = 0 ; y < YSIZE ; y++) {
  22.     for (x = 0 ; x < XSIZE ; x++) {
  23.         h[read_pixel(x,y)] = h[read_pixel(x,y)] + 1L;
  24.     }
  25.   }
  26.  
  27.  
  28.  
  29. listing 3 
  30.  
  31.   long h[256];
  32.  
  33. /* Histogram area, result into array h */
  34.   histogram(x,y,dx,dy,h);        /* SIMPP routine */
  35. /* Find the low and high bins based on minimum count of 30 */
  36.   clip_histo(h,30,&low_bin,&high_bin);    /* SIMPP routine */
  37. /* Compute the factor for stretching the in between values */
  38.   step = 256.0/(double)(high_bin-low_bin+1);  /* step delta */
  39.   step_value = 0.0;            /* Step value */
  40. /* Form a translation table (LUT), tran[] for enhancing
  41.    contrast */
  42. /* Values below low_bin are set to minimum pixel value */
  43.   for (i = 0 ; i < low_bin ; i++) tran[i] = 0;
  44. /* Values between low_bin and high_bin are stretched to range
  45.    from 0 to 255 */
  46.   for (i = low_bin ; i <= high_bin ; i++) {
  47.     tran[i] = step_value;
  48.     step_value += step;
  49.   }
  50. /* Values above high_bin are set to maximum pixel value */
  51.   for (i = high_bin+1 ; i < 256 ; i++) tran[i] = 255;
  52. /* Now point process area using the translation table, tran[] */
  53.   while (dy--) {
  54.     for (i = x; i < x + dx; i++) {
  55.         write_pixel(i,y,  tran[read_pixel(i,y)] );
  56.     }
  57.   }
  58.  
  59.  
  60.  
  61. listing 4
  62.  
  63. /* Change the output LUTs to display the pixel values *
  64.  * ranging from v_begin to v_end in red.          */
  65. LUT_highlight(v_begin,v_end)
  66. {
  67.   int i;
  68.  
  69. /* Set output tables to "linear".  This will display
  70.    the image in normal, monochrome fashion */
  71.   for (i = 0 ; i < 256 ; i++) {
  72.     write_LUT(RED,i,i);
  73.     write_LUT(GREEN,i,i);
  74.     write_LUT(BLUE,i,i);
  75.   }
  76. /* Set the desired range so that ONLY red is displayed */
  77.   for (i = v_begin ; i <= v_end ; i++) {
  78.     write_LUT(RED,i,255);    /* Full red */
  79.     write_LUT(GREEN,i,0);    /* No green */
  80.     write_LUT(BLUE,i,0);    /* No blue */
  81.   }
  82.  
  83.  
  84.  
  85. listing 5 
  86.  
  87. /* Set up kernel for "sharpening" (high-frequency boosting)
  88.    the image */
  89.   static int kernel[9] = {-1,-1,-1,
  90.               -1, 9,-1,
  91.               -1,-1,-1,};
  92.  
  93. /* Increment starting position and decrement image size to accommodate the
  94.    convolution edge effects */
  95.   x++; y++; dx--; dy--;
  96. /* Set up address offsets for the output */
  97.   xx = 0; yy = 0;
  98. /* Scan through source image, output to destination */
  99.   for (i = y ; i < y+dy ; i++) {
  100.      xx = 0;            /* Reset x output index */
  101.      for (j = x ; j < x+dx ; j++) {
  102.     sum = 0;        /* Zero convolution sum */
  103.     k_pointer = kernel;    /* Pointer to kernel values */
  104. /* Inner loop to do convolution (correlation!) */
  105.     for ( n = -1 ; n <= 1 ; n++) {
  106.       for (m = -1 ; m <= 1 ; m++)
  107.         sum = sum + read_pixel(j+m,i+n)*(*k_pointer++);
  108.      }
  109. /* Output processing */
  110.     if (sum < 0) sum = 0;
  111.     write_pixel(x_out + xx, y_out + yy, sum);
  112.     xx++;        /* Increment output X address offset */
  113.     } yy++;        /* Increment output Y address offset */
  114.   }
  115.  
  116.  
  117.  
  118. listing 6 
  119.  
  120. /* Variables used in labeling */
  121.   static int count;
  122.   static int newval = 1;
  123.  
  124. /* Search image area for target values == 255 */
  125.   for (y = 0 ; y < YSIZE ; y++) {
  126.     for (x = 0 ; x < XSIZE ; x++) {
  127. /* If we find a target value, recursively label
  128.    the connected pixels with a new value (newval) */
  129.     if (read_pixel(x,y) == 255) {
  130.         count = 0;    /* Zero pixel count */
  131.         recursive_label(x,y);
  132.         newval ++j
  133.     }
  134.     }
  135.   }
  136.  
  137.   recursive_label(x,y)
  138.   {
  139.     write_pixel(x,y,newval);    /* Replace with newval */
  140.     count++;            /* Increment count */
  141.  
  142. /* Recurse left */
  143.     x--;
  144.     if (read_pixel(x,y) == 255) recursive_label(x,y);
  145. /* Recurse right */
  146.     x += 2;
  147.     if (read_pixel(x,y) == 255) recursive_label(x,y);
  148.     x--;
  149. /* Recurse up (remember: video coordinates!) */
  150.     y--;
  151.     if (read_pixel(x,y) == 255) recursive_label(x,y);
  152. /* Recurse down */
  153.     y += 2;
  154.     if (read_pixel(x,y) == 255) recursive_label(x,y);
  155.   }
  156.  
  157.  
  158.  
  159. listing 7 
  160.  
  161.   int xs,ys;    /* Start of source */
  162.   int x,y;    /* Start of destination */
  163.   int dx,dy;    /* Size of destination area */
  164.   double a,b;    /* x,y scale factors */
  165.   xa,ya;    /* x and y addresses for source */
  166.  
  167.   for (i = 0 ; i < dy ; i++) {
  168.     for (j = 0 ; j < dx ; j++) {
  169.     xa = xs + (int)((double)j/a);    /* x address */
  170.     ya = ys + (int)((double)i/b);    /* y address */
  171. /* Write out new value to destination */
  172.     write_pixel(x+j, y+i, read_pixel(xa,ya));
  173.     }
  174.   }
  175.  
  176.  
  177.